Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
QUERY-PREPARE method
Once you’ve defined the buffers for a dynamic query, the next step is to provide it with a
FOR EACHstatement that it should use to retrieve and order data when you open the query. TheQUERY-PREPAREmethod takes theFOR EACHstatement as its argument. It returns true if the operation succeeded and false otherwise. You can useQUERY-PREPAREto define the record selection for a dynamic query or to change the selection for a static one. This sample code prepares the dynamic query for the Order, Customer, and SalesRep tables:
There are a few important comments to make about this example:
- Remember that when you use a one-to-one join in a
FOR EACHstatement for a query, you must include theFIRSTorEACHkeyword in each table phrase, as is shown in the following code example. Since there is just one Customer for each Order, and one SalesRep for each Order, there is no need to iterate through potentially multiple Customers or SalesReps for an Order, so theFIRSTkeyword suffices. In aFOR EACHstatement in a block header, theFIRSTkeyword would be optional, as in this example:
- If you know exactly what the
WHEREclause andBYclause are when you write the procedure, you might not need to use dynamic constructs at all. More realistically, you use theQUERY-PREPAREmethod when you don’t know the selection and sort criteria until run time. In the "Extending the sample window to filter dynamically" section, you’ll build an extension to the Customer and Orders window that shows this flexibility more realistically.- Since you normally use the
QUERY-PREPAREmethod in cases where theWHEREclause is truly variable, it is essential that you always assign the result of the method to a logical variable, and then check the value of that variable and theERROR-STATUS:NUM-MESSAGESvalue to be sure that the prepare succeeded. If it doesn’t and you continue without intercepting the error, your procedure generates a whole series of error statements as you attempt to open and use the query.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |